package zh.demo.webuser.controller;

import org.springframework.web.bind.annotation.*;
import zh.demo.commons.utils.R;
import zh.demo.webuser.annotation.AuthIgnore;
import zh.demo.webuser.annotation.LoginUser;
import zh.demo.webuser.model.TokenEntity;
import zh.demo.webuser.model.UserEntity;

/**
 * API测试接口
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-03-23 15:47
 */
@RestController
@RequestMapping("/api")
public class ApiTestController {

    /**
     * 获取用户信息
     */
    @GetMapping("userInfo")
    public R userInfo(@LoginUser UserEntity user){
        return R.ok().put("user", user);
    }

    /**
     * 忽略Token验证测试
     */
    @AuthIgnore
    @GetMapping("notToken")
    public R notToken(){
        String jsonStr = "{\"img\":\"http://img03.sogoucdn.com/net/a/04/link?appid=100520033&url=http%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2Fx6iaHWKibUzk0mmYP1Cyp9YibriaDBiacEuFSzUxz8Cxic43TOOaszqQomhaSjTwyoZqN2fmoBzr8wohoYk5EnGZ8Y2g%2F0%3Fwx_fmt%3Djpeg\",\"author\":\"新浪新闻 \",\"authorUrl\":\"http://mp.weixin.qq.com/profile?src=3&timestamp=1508470928&ver=1&signature=hQDpZ3Kj-jSImow1GKOSD9k5HYbv0VER36-NMwH5s07*4*7Bqu-vQ8OjrBU-YTy0ZQmH0n1G-oKDsvVkwVqXFQ==\",\"link\":\"http://mp.weixin.qq.com/s?src=11&timestamp=1508470928&ver=463&signature=U0-M654ZbLKx8FOZ93yhpBLBAo1HBGuaXaHT1gqOUyD2A5HrFYmtu-U9-0hxb8wWF1uTYU0kFmX-om6PzsgRQZS6-OT-Lr3B9q1y71rFwgWZKfO9GS7AE1Q3JP4OYhvS&new=1\",\"time\":\"1508465311\",\"title\":\"这五类房子很难转手，价格再低也不能买\",\"content\":\"导语今年的楼市调控不断发力，多个城市密集出台楼市调控措施，全国40余座城市开始“限购”或“限售”。但对于我们买房人来说，除了要关注调控政策，更要能够全方位思考房子的价值，比如市场上有几类房子很难转手...\"},{\"img\":\"http://img01.sogoucdn.com/net/a/04/link?appid=100520033&url=http%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FfPSa4zeEwhBNiaianGg6BOghWbgYchaNN1BiczI8Bf5UwgibvSh67BChibicEV7ekExcVacGqtSwzWjXcbWFxBxgpDqg%2F0%3Fwx_fmt%3Djpeg\",\"author\":\"扬子晚报 \",\"authorUrl\":\"http://mp.weixin.qq.com/profile?src=3&timestamp=1508470928&ver=1&signature=334uomYYEbjRaYvtfI*87GBZmW-gDDOjakPjdvmDurVe1up*8T4ttQndz-1kQ25b8*VUpe-l99bS1bfoxC-I1A==\",\"link\":\"http://mp.weixin.qq.com/s?src=11&timestamp=1508470928&ver=463&signature=IHpl-K76Vb7CksPGLaynp9R8kSIjXQE8DZBQeBrY0DtIBkgeA2nwPu1ZmcWPFGszCEp1izIo2M*SdPXauWAlcyBYgMgK3fdHmkNphehG9IEwaHBxz6m9TkZ-zYlDcYqX&new=1\",\"time\":\"1508464552\",\"title\":\"2块钱和98块钱的维生素C到底有什么区别?知道这些再不花冤枉钱\",\"content\":\"近日一篇关于维生素C的文章在朋友圈刷屏了：那天，在吃完一顿黄焖鸡打着嗝第二天醒来感受到来自上唇火烧火燎的灼痛后，我意识到我该补充维生素c了。“请给我拿一瓶维生素c。”柜员手脚麻利的从上层拿了一瓶酷似...\"}";
        return R.ok().put("data", jsonStr);
    }

    /**
     * 接收JSON数据
     */
    @PostMapping("jsonData")
    public R jsonData(@LoginUser UserEntity user, @RequestBody TokenEntity token){
        return R.ok().put("user", user).put("token", token);
    }
}
